        var windowSize="650px";
        var wms_bores_url = 'http://maps.ubspatial.com.au/groundwater/wms?service=WMS';
        var wms_salinity_url = 'http://maps.ubspatial.com.au/salinity/wms?service=WMS';
        var wms_cos_boundary_url = 'http://maps.ubspatial.com.au/cos_data_wms/wms?service=WMS';
        var tile_cache_url = 'http://maps.ubspatial.com.au/tc/';
        var gsv_wms_url = 'http://gsv-ws.dpi.vic.gov.au/SeamlessGeology/wms?service=WMS';
	var extent;
	var eventsLog = "";
	var c=0;
	var AutoSizeFramedCloud="";
	var markers="";
	var click_ll="";
	var mg_map;
	var popup="";
	var panel;
	var metersPerUnit = 1;
	var mg_wms_gsv1;
	var infoControls;
	var click;
	OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
	//OpenLayers.Util.onImageLoadError = function() { this.style.display = "none"; }
	//UBS
	//OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
	//AS
	OpenLayers.ProxyHost = "http://maps.ubspatial.com.au/cgi-bin/proxy.cgi?url=";
	
        function initTiled(){

		eventsLog = OpenLayers.Util.getElement("eventsLogID");	
        
		if(start_x){
			xStart = start_x;
		}
		else{
			xStart = 142.752186709067; 
		} 
		if(start_y){
			yStart = start_y;
		}
		else{
			yStart= -38.0104094721044; 
		} 
		
		var startCoord = new OpenLayers.LonLat(xStart,  yStart);
		if(start_zoom){
			var startZm = start_zoom;
		}
		else {
			var startZm = 0;
		}
		
		
		
		
		
        var mapOptions = {
          projection: new OpenLayers.Projection("EPSG:900913"),
          displayProjection: new OpenLayers.Projection("EPSG:4326"),
	      units: "m",
          maxResolution: 156543.0339,
          maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
          numZoomLevels: 10,
          maxZoomLevel: 18,
          minZoomLevel: 8,
          controls: [new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.ArgParser(), new OpenLayers.Control.Attribution()]
        };
           
        //initialise map and add extra controls 
        mg_map = new OpenLayers.Map( 'map_mg', mapOptions );
        layerSwitcher = new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')});
        mg_map.addControl(layerSwitcher);
        layerSwitcher.dataLbl.innerHTML = "<b>Layers</b>";
        layerSwitcher.baseLbl.innerHTML = "<b>Base maps</b>";
	mg_map.addControl(new OpenLayers.Control.ScaleLine());
	mg_map.addControl(new OpenLayers.Control.MousePosition({ div: document.getElementById('mapMousePosition'), numdigits: 6 }));            
        mg_map.addControl(new OpenLayers.Control.Scale('mapScale'));
        mg_map.addControl(new OpenLayers.Control.LoadingPanel({ 'div': document.getElementById('mapLoadingPanel')}));
                
        // display the map projection
        document.getElementById('mapProjection').innerHTML = mg_map.projection;
        
        // Create a Google streets layer
        var googleLayer = new OpenLayers.Layer.Google('Google Streets', {'sphericalMercator': true, numZoomLevels: 10});
        mg_map.addLayer(googleLayer);
   
        // Create a Google hybrid layer
        var googleHybridLayer = new OpenLayers.Layer.Google('Google Hybrid', {'sphericalMercator': true, type: google.maps.MapTypeId.HYBRID, numZoomLevels: 10});
        mg_map.addLayer(googleHybridLayer);
        
        //var googleSatelliteLayer = new OpenLayers.Layer.Google('Google Satellite', {'sphericalMercator': true, type: G_SATELLITE_MAP, numZoomLevels: 18});
        //mg_map.addLayer(googleSatelliteLayer);
        
	 	/*var bingLayer = new OpenLayers.Layer.VirtualEarth("Bing Maps Shaded", {
	 		'sphericalMercator': true, 
            type: VEMapStyle.Shaded, 
            isBaseLayer: true
        });
        mg_map.addLayer(bingLayer);*/
        
        var rand = Math.floor(Math.random()*11);
        
        
        // Add aerial imagery (Corangamite) layer using TMS tilecache
        //cma_image_bounds = new OpenLayers.Bounds(142.70258, -38.89448, 144.78998, -37.30817);
        //cma_image_bounds.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
        //UBS
	//cma_layer_label = "Aerial Imagery (Corangamite)" + "<img src='images/info_icon.png' alt='Corangamite CMA Region Only. Available at scale 1:250k' title='Corangamite CMA Region Only. Available from Scale 1:250k' class='layer_info_icon'/>"
	//AS
        cma_layer_label = "Aerial Imagery (Corangamite)" + "<img src='http://maps.ubspatial.com.au/images/info_icon.png' alt='Corangamite CMA Region Only. Available at scale 1:250k' title='Corangamite CMA Region Only. Available from Scale 1:250k' class='layer_info_icon'/>"
        cma_image_layer = new OpenLayers.Layer.TMS(cma_layer_label, [tile_cache_url], {layername: 'Corangamite', type:'png', buffer:1, numZoomLevels: 18, zoomOffset: 8, maxZoomLevel: 2, 'getURL':getTileUrl} );
        cma_image_layer.addOptions({isBaseLayer: false});
        cma_image_layer.addOptions({minScale: 250000});
        //cma_image_layer.addOptions({maxExtent: cma_image_bounds});
        cma_image_layer.setVisibility(false);
        //cma_image_layer.addOptions({minScale: 2000000});
        mg_map.addLayer(cma_image_layer);
        
        // Add aerial imagery (Colac 1946) layer using TMS tilecache
        //UBS
	//colac_layer_label = "Aerial Imagery Colac 1946" + "<img src='images/info_icon.png' alt='Colac Region Only. Available at scale 1:250k' title='Colac Region Only. Available from Scale 1:250k' class='layer_info_icon'/>"    
        //AS
	colac_layer_label = "Aerial Imagery Colac 1946" + "<img src='http://maps.ubspatial.com.au/images/info_icon.png' alt='Colac Region Only. Available at scale 1:250k' title='Colac Region Only. Available from Scale 1:250k' class='layer_info_icon'/>"    
        colac_image_layer = new OpenLayers.Layer.TMS(colac_layer_label, [tile_cache_url], {layername: 'colac_1946', type:'png', buffer:1, numZoomLevels: 18, zoomOffset: 8, maxZoomLevel: 2, 'getURL':getTileUrl2} );
        colac_image_layer.addOptions({isBaseLayer: false});
        colac_image_layer.addOptions({minScale: 250000});
        colac_image_layer.setVisibility(false);
        colacBounds = new OpenLayers.Bounds(142.985770, -38.896550, 143.935100, -38.366650);
        colacBounds.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
        //alert(colacBounds.left);
        //alert(colacBounds.right);
        //alert(colacBounds.top);
        //alert(colacBounds.bottom);
        mg_map.addLayer(colac_image_layer);
        
        
        if(shire_map=="cos"){
        	cos_wms_boundary = new OpenLayers.Layer.WMS( "COS Boundary", wms_cos_boundary_url, {layers: 'COS Outline Region', transparent: true});
        	cos_wms_boundary.addOptions({isBaseLayer: false, singleTile: true, displayInLayerSwitcher: false});
        	cos_wms_boundary.setVisibility(true);
        	mg_map.addLayer(cos_wms_boundary);
        }
        
        //Add groundwater bores layer
        mg_wms_bores = new OpenLayers.Layer.WMS( 
		"Bores", 
		wms_bores_url, 
		{
			layers: 'groundwater_bores,other_bores', 
			transparent: true
		}
	);
        mg_wms_bores.addOptions({
		isBaseLayer: false, 
		singleTile: true, 
		opacity: 0.6
	});
        mg_wms_bores.setVisibility(true);
        mg_wms_bores.events.register('visibilitychanged', this, displayLegend);
        mg_map.addLayer(mg_wms_bores);
        
        //Add salinity polygons layer
        mg_wms_salinity = new OpenLayers.Layer.WMS(
		"Salinity", 
		wms_salinity_url, 
		{
			layers: 'salinity_polygons', 
			transparent: true
		}
	);
        mg_wms_salinity.addOptions({
		isBaseLayer: false, 
		singleTile: true
	});
        mg_wms_salinity.setVisibility(false);
        mg_wms_salinity.events.register('visibilitychanged', this, displayLegend);
        mg_map.addLayer(mg_wms_salinity);
        
        //Add Seamless Geology layer from Geoscience Victoria
        //UBS
	//gsv_acknowledgement = "<img src='images/info_icon.png' alt='WMS Service Provided by GeoScience Victoria. Available at scale 1:900k' title='WMS Service Provided by GeoScience Victoria. Available at scale 1:900k' class='layer_info_icon'/>"
	//AS
        gsv_acknowledgement = "<img src='http://maps.ubspatial.com.au/images/info_icon.png' alt='WMS Service Provided by GeoScience Victoria. Available at scale 1:900k' title='WMS Service Provided by GeoScience Victoria. Available at scale 1:900k' class='layer_info_icon'/>"
        gsv_layer_label = "Geology" + gsv_acknowledgement;
        mg_wms_gsv1 = new OpenLayers.Layer.WMS( 
		gsv_layer_label, 
		gsv_wms_url, 
		{
			layers: 'gsv:GSV_SG_250K_GEOLUNIT', 
			transparent: true
		}
	);
        mg_wms_gsv1.addOptions({
		isBaseLayer: false, 
		singleTile: true, 
		opacity: 0.8
	});
        mg_wms_gsv1.addOptions({minScale: 900000});
        mg_wms_gsv1.setVisibility(false);
        mg_wms_gsv1.events.register('visibilitychanged', this, layerChanged); 
        mg_map.addLayer(mg_wms_gsv1);
    
/*
	//Add redlining layer for displaying user added shapes/points
	redlining_layer = new OpenLayers.Layer.WMS( 
		"Comments", 
                "http://gis2.cecc.com.au/cgi-bin/mapserv?" +
                  "map=/opt/fgs/apps/gmap-demo-cvs_MS_VERSION_54/htdocs/feedback_wms.map" +
                  "&service=WMS" +
                  "&BGCOLOR=0xFFFFFF" +
                  "&TRANSPARENT=TRUE", 
		{
			layers: 'Feedback_polygons,Feedback_points', 
			transparent: true
		}
	);         
        redlining_layer.addOptions({
		isBaseLayer: false, 
		singleTile: true
	});
	mg_map.addLayer(redlining_layer);
*/

/*	
        // Add some tools
        var zoomBox = new OpenLayers.Control.ZoomBox(
            {title:"Zoom Rectangle: Use this tool to zoom to an area by clicking and dragging."});
        var mouseDefaults = new OpenLayers.Control.MouseDefaults(
            {title:'Pan: Use this tool to pan around the map.'});
        var zoomExtents = new OpenLayers.Control.ZoomToMaxExtent(
            {title:"Zoom Extents: Zoom to the max extent of the map"}) ;
        var panel = new OpenLayers.Control.Panel({defaultControl: zoomBox});
        panel.addControls([mouseDefaults, zoomBox, zoomExtents]);
        mg_map.addControl(panel);
*/

        // Add layers for displaying map markers. eg. for highlighting an address search result
        layerMarkers = new OpenLayers.Layer.Markers("Markers");
        layerMarkers.addOptions({displayInLayerSwitcher: false});
	mg_map.addLayer(layerMarkers);

	// Add a vector layer to allow user redlining on the map. This is connected to the featureIsAdded function for collecting the users comments
        //UBS
	//vlayer = new OpenLayers.Layer.Vector( "Editable", {onFeatureInsert: featureIsAdded});
        //AS
	vlayer = new OpenLayers.Layer.Vector( "Editable", {onFeatureInsert: profileIsAdded});
        vlayer.addOptions({displayInLayerSwitcher: false});
        mg_map.addLayer(vlayer);
        var container = document.getElementById("panel");
        panel = new OpenLayers.Control.EditingToolbar(vlayer, {div: container});
        mg_map.addControl(panel);
	    
	    click = new OpenLayers.Control.Click();
        mg_map.addControl(click);
        click.activate();
	    
        
        // If lat/lon specified then assume bore search and zoom/centre map on that point
	    if(this_lon){
	    	bore_lonlat = new OpenLayers.LonLat(this_lon,this_lat);
	    	bore_lonlat.transform(new OpenLayers.Projection("EPSG:4326"), mg_map.getProjectionObject()); 
	    	mg_map.setCenter(bore_lonlat, 8);
	    }
	    else{
	    	startCoord.transform(new OpenLayers.Projection("EPSG:4326"), mg_map.getProjectionObject());   	
	    	mg_map.setCenter(startCoord,  startZm);
	    	//mg_map.setCenter(extent.getCenterLonLat());
	    }  
	    
	    
	    // Set up WMS querying for GSV Geology layer.
	    
	    infoControls =
	    {
	    	click: new OpenLayers.Control.WMSGetFeatureInfo
		    	({
		    	url: gsv_wms_url,
		    	title: 'Identify features by clicking',
		    	layers: Array(mg_wms_gsv1),
		    	queryVisible: true,
		    	infoFormat:'text/html'
		    	})
	    }
        
	    infoControls['click'].events.register("beforegetfeatureinfo", this, showProgress);
	    infoControls['click'].events.register("getfeatureinfo", this, showInfo);
        mg_map.addControl(infoControls['click']);
	    
        displayLegend();
	}	
	
        // Set up querying for bores and salinity layers
        
        OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                
                defaultHandlerOptions: {
                    'single': true,
                    'double': false,
                    'pixelTolerance': 0,
                    'stopSingle': false,
                    'stopDouble': false
                },

                initialize: function(options) {
                    this.handlerOptions = OpenLayers.Util.extend(
                        {}, this.defaultHandlerOptions
                    );
                    OpenLayers.Control.prototype.initialize.apply(
                        this, arguments
                    ); 
                    this.handler = new OpenLayers.Handler.Click(
                        this, {
                            'click': this.trigger
                        }, this.handlerOptions
                    );
                }, 

                trigger: function(e) {
                click_ll = mg_map.getLonLatFromViewPortPx(e.xy);
                click_ll2 = mg_map.getLonLatFromViewPortPx(e.xy);
                //alert(click_ll.lat + " " + click_ll.lon);
                click_ll2.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
                //alert(click_ll.lat + " " + click_ll.lon);
                if(ccma_map){
                	//UBS
			//var url =  'bore_popup_ccma.php?lat='+click_ll2.lat + '&lon=' + click_ll2.lon +'&';
                	//AS
			var url =  'http://maps.ubspatial.com.au/bore_popup_ccma.php?lat='+click_ll2.lat + '&lon=' + click_ll2.lon +'&';
                }
                else{
    	        	//UBS
			//var url =  'bore_popup.php?lat='+click_ll2.lat + '&lon=' + click_ll2.lon +'&';
    	        	//AS
			var url =  'http://maps.ubspatial.com.au/bore_popup.php?lat='+click_ll2.lat + '&lon=' + click_ll2.lon +'&';
                }
    	        //alert(url);  //AS uncommented.
        	    //UBS
		    //OpenLayers.loadURL(url, '', this, setHTML);
		    //AS
		    OpenLayers.Request.GET({
			    url: url,
			    proxy: '/cgi-bin/proxy.cgi?url=',  //AS doesn't work with UBS proxy.
			    callback: setHTML,
			    failure: failed
		    });
		//AS
		//alert("OpenLayers returned after URL GET\n"+url);
            	    //OpenLayers.Event.stop(e);
                    //var lonlat = map.getLonLatFromViewPortPx(e.xy);
                }

            });
	
	    function failed(response){alert("Failed; Response= >"+response.responseText+"<");}
	    function setHTML(response) {
	    	// function to create popup response for bore query. 
			//AS
		        //alert("Response= >"+response.responseText+"<");
	    	
			if (response.responseText.length > 1){
				//alert(response.responseText);
			if (popup){
				mg_map.removePopup(popup);
			}
			popup = new OpenLayers.Popup.FramedCloud("bore",
                                     click_ll,
                                     new OpenLayers.Size(100,100),
                                     response.responseText,
                                     null, true, null);
			mg_map.addPopup(popup);

			}
	    }
	    
	    function showInfo(evt) {
	    	// function to create popup response for GSV geology query
	    	if (evt.text) {
	    		
	            var unit_name =  $(evt.text).find('td:eq(5)').text();
	            var unit_desc =  $(evt.text).find('td:eq(9)').text();
	            var unit_age =   $(evt.text).find('td:eq(11)').text();
	            
	            click_ll = mg_map.getLonLatFromViewPortPx(evt.xy);
               // click_ll2 = mg_map.getLonLatFromViewPortPx(e.xy);
                //alert(click_ll.lat + " " + click_ll.lon);
               // click_ll2.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
	            
	            var popup_html = "<html><body><h4>Seamless Geology</h4><b>Unit:</b> " + unit_name + "<br><b>Age:</b> " + unit_age + "<p style='width:200px;'>" + unit_desc + "</p></body></html>";
	            if (popup){
					mg_map.removePopup(popup);
	            }
				popup = new OpenLayers.Popup.FramedCloud(
						"bore",
                        click_ll,
                        new OpenLayers.Size(200,100),
                        popup_html,
                        null, true, null
	            );
				mg_map.addPopup(popup);
				hideProgress();
	            //var feature_id =  parseInt($(evt.text).find('td:eq(1)').text());
	           // alert(feature_id);
				/*if(isNaN(feature_id)){
				}
				else{
					var resource_url = 'http://www.ccmaknowledgebase.vic.gov.au/resource_list.php?accordion=2&action=search&feature_id=' + feature_id + '&layer=' + layer_name;
					window.top.location = resource_url;
				} */
	    	}
	    }
	    
	    function showProgress(){
	    	$("#wmsLoadingPanel").css("display","block");
	    }
	    
	    function hideProgress(){
	    	$("#wmsLoadingPanel").css("display","none");
	    }
	    
	    function layerChanged(layer) { 
	    	/*
	    	 * This function will activate/deactivate querying controls as verious layers are turned on/off. 
	    	 * This is so mouse-click querying functions can still work without making the user enter querying mode. 
	    	*/
	        if (layer.object.visibility) {
	        	infoControls['click'].activate();
	        	panel.deactivate();
	        	click.deactivate();
	        	$("#general-info-box").css("display", "none");
	        	$("#geology-info-box").css("display", "block");
	        } 
	        else{
	        	infoControls['click'].deactivate();
	        	panel.activate();
	        	click.activate();
	        	$("#geology-info-box").css("display","none");
	        	$("#general-info-box").css("display","block");
	        }
	        
	    } 
	    
	    function export_map_bores(){
	    	//Get the  boundaries of the current map and pass them to the bore export page
	    	
	    	var map_resolution = mg_map.getResolution(); 
	    	var map_center = mg_map.getCenter();
	    	
	    	var map_bounds = mg_map.calculateBounds(map_center,mg_map.resolution);
	    	
	    	map_bounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
	    	var params = 'top='+map_bounds.top+'&bottom='+map_bounds.bottom+'&left='+map_bounds.left+'&right='+map_bounds.right;
	    	
	    	window.open('http://www.ubspatial.com.au/ccma_bores/admin/bore_export.php?'+params,'bore_export')
	    	
	    }


	    function navigateToAddress(lat, lon, zoom, addmarker){
	    	//alert(lat+" "+lon);
	    	var lonLat = new OpenLayers.LonLat(lon, lat);
	    	var lonLat2 = new OpenLayers.LonLat(lon, lat);
	    	lonLat2.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
	  		mg_map.setCenter(lonLat2, 8);
	  		
		  	var size = new OpenLayers.Size(21,25);
			var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
			var icon = new OpenLayers.Icon('http://gis2.cecc.com.au/cecc/openlayers-2.10/img/marker-green.png',size,offset);
			layerMarkers.clearMarkers();
			if(addmarker){
				layerMarkers.addMarker(new OpenLayers.Marker(lonLat2,icon));
			}

	  	  }

	    function featureIsAdded(feature){
	    	// Activated when a user completes adding a point/shape using the redlining feature. Saves the shape and activates dialog to collect comments
	    	feature.geometry.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
	         //alert("Feature with id: "+feature.id+", has following Geometry:"+feature.geometry +" " +feature.geometry);
	         //if its a point, set appropriate form values
	         if(feature.geometry.y){
	         	$('#lat').val(feature.geometry.y);
	         }
	         if(feature.geometry.x){
	         	$('#lon').val(feature.geometry.x);
	         }
	    	 // otherwise if its a polygon or line set the shape field to WKT value
	         if(!feature.geometry.x){
	         	$('#shape').val(feature.geometry);
	         }
	         
	         $('#action').val("add");
	         //alert(panel);
	         panel.controls[1].deactivate();
	         panel.controls[2].deactivate();
	         panel.controls[3].deactivate();
	         panel.controls[0].activate();
	         //$('.olControlEditingToolbar div:first').trigger('click');
	    	$('#dialog').dialog('open');
	    }
	    
	    function profileIsAdded(feature){
	    	// Activated when a user completes adding a point/shape using the redlining feature. Then calculates a vertical section.
	    	feature.geometry.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
	        alert("Feature with id: "+feature.id+" has the following geometry: "+feature.geometry);
	        
		//if its a point, set appropriate form values
	        if(feature.geometry.y){
	         	$('#lat').val(feature.geometry.y);
	        }
	        if(feature.geometry.x){
	         	$('#lon').val(feature.geometry.x);
	        }
	    	
		// otherwise if its a polygon or line set the shape field to WKT value
	        if(!feature.geometry.x){
	         	$('#shape').val(feature.geometry);
	        }
	         
	        $('#action').val("add");
	        //alert(panel);
	        panel.controls[0].activate();
	        panel.controls[1].deactivate();
	        panel.controls[2].deactivate();
	        panel.controls[3].deactivate();
	        //$('.olControlEditingToolbar div:first').trigger('click');
	    	//$('#dialog').dialog('open');
	    }
	    
	    function displayLegend(){
	    	// loop through active layers and display legend graphic for each
	    	
	    	wms_bores_legend_url1 = wms_bores_url + '&request=getlegendgraphic&format=image/png&version=1.1.1&layer=groundwater_bores';
	    	wms_bores_legend_url2 = wms_bores_url + '&request=getlegendgraphic&format=image/png&version=1.1.1&layer=other_bores';
	    	wms_salinity_legend_url = wms_salinity_url + '&request=getlegendgraphic&format=image/png&version=1.1.1&layer=Salinity_polygons';
	    	legend_html ='';
	    	
	    	activeLayers = mg_map.getLayersBy("visibility", true);
	    	for (var i=0; i<activeLayers.length;i++) {
	    		 var layer = activeLayers[i];
	    		 
	    		if((!layer.isBaseLayer) && (layer.displayInLayerSwitcher)){
	    			if(layer.name == "Bores"){
	    				legend_html = legend_html + "<img src='" + wms_bores_legend_url1 + "'>" + "<img src='" + wms_bores_legend_url2 + "'>";
	    			}
	    			if(layer.name == "Salinity"){
	    				legend_html = legend_html + "<img src='" + wms_salinity_legend_url + "'>";
	    			}
	    		}
	    		//alert(legend_html);
	    	}
	    	$('#tabs-1').html(legend_html);
	    	
	    }
	    
	    function getTileUrl (bounds)
	    {
	    	
	          if (bounds.left   < 15885578.538275 ||
	              bounds.right  > 16117946.843325 ||
	              bounds.top    > -4482149.203779 ||
	              bounds.bottom < -4906567.9884024 ||
	              mg_map.getZoom() < 2)
	          {
	                  //UBS
			  //return 'images/blanktile.png';
			  //AS
	                  return 'http://maps.ubspatial.com.au/images/blanktile.png';
	          }
	    
	          var res = mg_map.getResolution();
	          var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
	          var y = Math.round ((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
	          var z = mg_map.getZoom() + 8;
	          //alert("tms/" + z + "/" + x + "/" + y + "." + this.type);
	          return tile_cache_url + "1.0.0/Corangamite/" + z + "/" + x + "/" + y + "." + this.type; 
	     }    
	    
	    function getTileUrl2 (bounds)
	    {
	    	
	          if (bounds.left   < 15917103.104868 ||
	              bounds.right  > 16022782.037049 ||
	              bounds.top    > -4631351.4283547 ||
	              bounds.bottom < -4706864.0614143 ||
	              mg_map.getZoom() < 2)
	          {
	                  //UBS
			  //return 'images/blanktile.png';
			  //AS
	                  return 'http://maps.ubspatial.com.au/images/blanktile.png';
	          }
	    
	          var res = mg_map.getResolution();
	          var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
	          var y = Math.round ((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
	          var z = mg_map.getZoom() + 8;
	          //alert("tms/" + z + "/" + x + "/" + y + "." + this.type);
	          return tile_cache_url + "1.0.0/colac_1946/" + z + "/" + x + "/" + y + "." + this.type; 
	     }    

